/**************************************************************************
	Replication do-file: "Corruption in Customs"
	Cyril Chalendard, Ana Fernandes, Gael Raballand and Bob Rijkers
	
	Created on: 01/07/2022
**************************************************************************/

clear all
set more off, perm
cap log close
cls

* Extra commands: remove the asterisk to install
*net install cleanplots, from("https://tdmize.github.io/data/cleanplots")
*set scheme cleanplots, perm

* ----------------------- DIRECTORIES AND FOLDERS ----------------------- *

* Directories in which data are stored
global main "PUT YOUR DIRECTORY PATH HERE"
cd "$folder"

* Folders
global outputdata = "$main\Output Data"
cap mkdir "$main\Figures"
global figures = "$main\Figures"

* ----------------------------- BEGINS HERE ----------------------------- *

* -------
* Dataset
* -------
use "$outputdata\CFRR.dta", clear // open dataset

* New variables
gen predicted = (ms_b-eis_f)

* Rename variables
rename (ms_b ia_ms_b) (observed initial)


* --------
* Figure 2
* --------

twoway (hist predicted if sample_reg==1 & observed<0.30 & observed>=0 & predicted<0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs3) lpattern(solid) lwidth(vvthin) fcolor(gs3*0.4)) ///
	|| (hist observed if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs9) lpattern(solid) lwidth(vvthin) fcolor(gs9*0.4)) ///
	|| (kdensity predicted if sample_reg==1 & observed<0.30 & observed>=0 & predicted<0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs4) lpattern(solid) lwidth(medthick)) ///
	(kdensity observed if sample_reg==1 & observed<0.30 & observed>=0 & predicted<=0.30 & predicted>=0 & initial>=0 & initial<0.3, lcolor(gs7) lpattern(dash) lwidth(medthick)), ///
	xlabel(, nogrid) ///
	ylabel(, angle(0) labsize(small) nogrid) ///
	ytitle("Frequency", size(small) color(black)) ///
	xtitle("Inspector share of a given broker's declarations", size(small) color(black)) ///
	legend(pos(6) ring(10) col(2) order(1 "Predicted assignment (histogram)" 2 "Observed assignment (histogram)" 3 "Predicted assignment (density)" 4 "Observed assignment (density)") size(small)) ///
	name(Figure_2, replace)
graph export "$figures\Figure_2.eps", as(eps) replace
graph export "$figures\Figure_2.pdf", as(pdf) replace


* -------------------------------- ENDS HERE -------------------------------- *